<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <script src="jquery1.11.0.min.js"></script>
    <script>
        $(function(){
            $('#btn').click(function(){
                console.log(111);
                //console.log($('form:eq(0)').serialize());
                var formData = {
                    username: $('#username').val(),
                    password: $('#password').val()
                };
                console.log(formData);
                console.log(JSON.stringify(formData));
                $.ajax({
                    type: 'post',
                    url: 'http://localhost:3000/login',
                    contentType: 'application/json',
                    dataType: 'text',
                    // data: $('form:eq(0)').serialize(),
                    data: JSON.stringify(formData),
                    success: function(_data) {
                        console.log(_data);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <div>
        <h3>POST提交</h3>
        <form action="http://localhost:3000/login" method="POST">
            用户名：<input type="text" name="username" id="username"><br>
            密码：<input type="password" name="password" id="password"><br>
            <input id="btn" type="button" value="登录">
        </form>
    </div>
</body>
</html>